#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
    //创建管道
    int fd[2] = {0};
    if(pipe(fd) < 0)
    {
        perror("pipe");
        return 1;
    }
    pid_t id = fork();
    if(id == 0)
    {
        //子进程
        close(fd[0]); //关闭读端
        const char* msg = "hihihihihi\n";
        int count = 100;
        while(count--)
        {
            write(fd[1],msg,sizeof(msg));
            sleep(1);
        }
        close(fd[1]);
        exit(1);
    }
        //父进程,直接将读端写端都关闭，导致子进程直接被杀掉
        close(fd[1]);
        close(fd[0]);
        int statu = 0;
        waitpid(id,&statu,0);

        printf("子进程捕捉到的信号: %d\n",statu & 0x7F);
    return 0;
}